import * as ErrorTypeEnum from './consts/ErrorTypeEnum';

/**
 * Class that represents an error, with consistent structure that will be used across the framework.
 * @class
 */
export default class ErrorObj {
  /**
   * @constructor
   * @param {ErrorTypeEnum} type The type of the error.
   * @see ErrorTypeEnum
   * @param {String|Array|MessageGroup} messages The messages of this error.
   * The value can be a string, a array of strings, or a instance of MessageGroup.
   * @param {Object} data Any additional data.
   */
  constructor(type = ErrorTypeEnum.APP, message, data = {}) {
    this.type = type;
    this.message = message;
    this.data = data;
  }
  /**
   * Detect whether the error object is an exception.
   * @static
   */
  static isException(error) {
    return error instanceof Error;
  }

  /**
   * Detect whether the error object is an instance of ErrorObj.
   * @static
   */
  static isErrorObj(error) {
    return error instanceof ErrorObj;
  }
}
